local juling = fk.CreateSkill{
  name = "spiritualPower&"
}

Fk:loadTranslationTable{
  ["spiritualPower&"] = "聚灵",
  ["#JulingDraw"] = "聚灵：可以移除任意枚「灵力」并摸等量的牌",
  ["#JulingGet"] = "聚灵：可以移除2枚「灵力」并从3个随机技能中选择一个获得",
}

local SeabornUtil = require "packages/seaborn/utility/utility"

juling:addEffect("active", {
  anim_type = "drawcard",
  target_num = 0,
  prompt = "#JulingDraw",
  interaction = function (self, player)
    return UI.Spin { from = 1, to = SeabornUtil.getSpiritualPower(player), }
  end,
  can_use = function (self, player)
    return SeabornUtil.getSpiritualPower(player) > 0 and player:usedSkillTimes(juling.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = effect.from
    local num = self.interaction.data
    SeabornUtil.addSiritualPower(player, -num)
    player:drawCards(num, juling.name)
  end,
})

juling:addEffect(fk.TurnStart, {
  priority = 0.001,
  can_trigger = function (self, event, target, player, data)
    return target == player and SeabornUtil.getSpiritualPower(player) > 1
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = juling.name,
      prompt = "#JulingGet"
    })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    SeabornUtil.addSiritualPower(player, -2)
    local skills = SeabornUtil.getSkills(room, 3)
    local choice = room:askToChoice(player, {
      choices = skills,
      detailed = true,
      skill_name = juling.name,
      cancelable = false
    })
    if choice then
      SeabornUtil.setJulingSkill(player, choice)
    end
  end,
})

return juling